//
// OpenTemplate
// Copyright (c) 2006
// by OpenArrow Software ( http://www.openarrow.com )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//

using System;
using System.CodeDom;

using OpenArrow.Reporting;
using OpenArrow.Templating.Parsing;
using OpenArrow.Templating.Properties;

namespace OpenArrow.Templating.Directives
{
    /// <summary>
    /// Represents the context information available when executing a Directive
    /// <seealso cref="OpenArrow.Templating.Directives.IDirective"/>
    /// </summary>
    public class DirectiveContext
    {
        #region Private Fields

        private ParsedTemplate parsedTemplate;
        private CodeTypeDeclaration templateType;
        private CodeCompileUnit templateCompileUnit;
        private ProblemCollection problems;
        private IProgressReporter reporter; 

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets the <see cref="OpenArrow.Templating.Parsing.ParsedTemplate"/> generated by the Parser
        /// </summary>
        public ParsedTemplate ParsedTemplate
        {
            get { return parsedTemplate; }
        }

        /// <summary>
        /// Gets the <see cref="System.CodeDom.CodeTypeDeclaration"/> that is being generated by the Template Generator
        /// </summary>
        public CodeTypeDeclaration TemplateType
        {
            get { return templateType; }
        }

        /// <summary>
        /// Gets the <see cref="System.CodeDom.CodeCompileUnit"/> that contains <see cref="TemplateType"/>
        /// </summary>
        public CodeCompileUnit TemplateCompileUnit
        {
            get { return templateCompileUnit; }
        }

        /// <summary>
        /// Gets a collection of problems that occurred during the entire template execution
        /// </summary>
        /// <remarks>Use this collection to indicate any errors that occur during execution</remarks>
        public ProblemCollection Problems
        {
            get { return problems; }
        }

        /// <summary>
        /// Gets an <see cref="OpenArrow.Reporting.IProgressReporter"/> to report progress to during execution
        /// </summary>
        public IProgressReporter Reporter
        {
            get { return reporter; }
            set { reporter = value; }
        } 

        #endregion

        #region Public Constructor

        /// <summary>
        /// Initializes a new instance of the DirectiveContext class.
        /// </summary>
        /// <param name="parsedTemplate">The <see cref="OpenArrow.Templating.Parsing.ParsedTemplate"/> generated by the Parser</param>
        /// <param name="templateType">The <see cref="System.CodeDom.CodeTypeDeclaration"/> that is being generated by the Template Generator</param>
        /// <param name="templateCompileUnit">The <see cref="System.CodeDom.CodeCompileUnit"/> that contains <see cref="TemplateType"/></param>
        /// <param name="problems">A collection of problems that occurred during the entire template execution</param>
        /// <param name="reporter">An <see cref="OpenArrow.Reporting.IProgressReporter"/> to report progress to during execution</param>
        /// <!--<exception cref="ArgumentNullException">
        /// One or more of <paramref name="parsedTemplate"/>, <paramref name="templateType"/>, 
        /// <paramref name="templateCompileUnit"/>, <paramref name="problems"/> is <see langword="null"/>
        /// </exception>-->
        /// <exception cref="ArgumentNullException"><paramref name="parsedTemplate"/> is <see langword="null"/></exception>
        /// <exception cref="ArgumentNullException"><paramref name="templateType"/> is <see langword="null"/></exception>
        /// <exception cref="ArgumentNullException"><paramref name="templateCompileUnit"/> is <see langword="null"/></exception>
        /// <exception cref="ArgumentNullException"><paramref name="problems"/> is <see langword="null"/></exception>
        public DirectiveContext(ParsedTemplate parsedTemplate, CodeTypeDeclaration templateType, CodeCompileUnit templateCompileUnit, ProblemCollection problems, IProgressReporter reporter)
        {
            if (parsedTemplate == null)
                throw new ArgumentNullException(String.Format(Resources.Exception_ArgIsNull, "parsedTemplate"), "parsedTemplate");
            if (templateType == null)
                throw new ArgumentNullException(String.Format(Resources.Exception_ArgIsNull, "templateType"), "templateType");
            if (templateCompileUnit == null)
                throw new ArgumentNullException(String.Format(Resources.Exception_ArgIsNull, "templateCompileUnit"), "templateCompileUnit");
            if (problems == null)
                throw new ArgumentNullException(String.Format(Resources.Exception_ArgIsNull, "problems"), "problems");
            if (reporter == null)
                reporter = new NullProgressReporter();

            this.parsedTemplate = parsedTemplate;
            this.templateType = templateType;
            this.templateCompileUnit = templateCompileUnit;
            this.problems = problems;
            this.reporter = reporter;
        }

        #endregion
    }
}
